#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int modd = 114514;
const int N = 1919810;
int n,t,m;
void solve(){
ll ap1,ap2,num1,num2,dam1,dam2;
cin >> ap1 >> ap2 >> num1 >> num2 >> dam1 >> dam2;
if(dam1 > dam2){
swap(dam1,dam2);
swap(num1,num2);
}
ll ans = 0;
for(ll i = 0; i <= num1; i ++){
ll used1 = i;
ll yushu1 = ap1 - i*dam1;
if(yushu1 < 0) break;
ll used2 = min(num2,yushu1/dam2);
yushu1 -= used2*dam2;
ll nownum1 = num1 - used1;
ll nownum2 = num2 - used2;
ll used1_ = min(nownum1,ap2/dam1);
ll yushu2 = ap2 - used1_*dam1;
ll used2_ = min(nownum2,yushu2/dam2);
ll num = used1 + used2 + used1_ + used2_;
ans = max(ans,num);
}
cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> t;
while(t --){
solve();
}
return 0;
}
791. Custom Sort String | 787. Cheapest Flights Within K Stops |
779. K-th Symbol in Grammar | 701. Insert into a Binary Search Tree |
429. N-ary Tree Level Order Traversal | 739. Daily Temperatures |
647. Palindromic Substrings | 583. Delete Operation for Two Strings |
518. Coin Change 2 | 516. Longest Palindromic Subsequence |
468. Validate IP Address | 450. Delete Node in a BST |
445. Add Two Numbers II | 442. Find All Duplicates in an Array |
437. Path Sum III | 436. Find Right Interval |
435. Non-overlapping Intervals | 406. Queue Reconstruction by Height |
380. Insert Delete GetRandom O(1) | 332. Reconstruct Itinerary |
368. Largest Divisible Subset | 377. Combination Sum IV |
322. Coin Change | 307. Range Sum Query - Mutable |
287. Find the Duplicate Number | 279. Perfect Squares |
275. H-Index II | 274. H-Index |
260. Single Number III | 240. Search a 2D Matrix II |